package com.yanqu.road.server.cmd.activity.rankunionwar;

import com.yanqu.road.entity.activity.rankunionwar.config.RankUnionWarConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.RankUnionWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.rankunionwar.RankUnionWarModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.rankunionwar.RankUnionWarMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_RANKUNIONWAR_BOX_OPEN, desc = "")
public class RankUnionWarOpenBoxReqCmd extends AbstractCommand {

    RankUnionWarProto.RankUnionWarBoxOpenReqMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = RankUnionWarProto.RankUnionWarBoxOpenReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        RankUnionWarConfig config = RankUnionWarMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        ret = player.getModule(RankUnionWarModule.class).openBox(reqMsg.getFloor(),reqMsg.getId());
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret == 0) {
            return;
        }
        RankUnionWarProto.RankUnionWarBoxOpenRespMsg.Builder respMsg = RankUnionWarProto.RankUnionWarBoxOpenRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(ClientProtocol.U_RANKUNIONWAR_BOX_OPEN, respMsg);
    }

}
